add test cfg/ignore_version_from_other_platform
authorWim Hueskes <rust@wimhueskes.eu>
Mon, 26 Sep 2016 22:46:10 +0000 (00:46 +0200)
committerWim Hueskes <rust@wimhueskes.eu>
Mon, 26 Sep 2016 22:59:23 +0000 (00:59 +0200)
if different platforms have a dependency to a different
version of a crate, only the correct dependency should
be downloaded and used

tests/cfg.rs

index e8de0101beb41a88bc6f47c51afbb87487b03dba..6712af6d8694a92be92d7bd13b374c2882fab788 100644 (file)
@@ -228,6 +228,38 @@ fn works_through_the_registry() {
 "));
 }
 
+#[test]
+fn ignore_version_from_other_platform() {
+    let this_family = if cfg!(unix) {"unix"} else {"windows"};
+    let other_family = if cfg!(unix) {"windows"} else {"unix"};
+    Package::new("foo", "0.1.0").publish();
+    Package::new("foo", "0.2.0").publish();
+
+    let p = project("a")
+        .file("Cargo.toml", &format!(r#"
+            [package]
+            name = "a"
+            version = "0.0.1"
+            authors = []
+
+            [target.'cfg({})'.dependencies]
+            foo = "0.1.0"
+
+            [target.'cfg({})'.dependencies]
+            foo = "0.2.0"
+        "#, this_family, other_family))
+        .file("src/lib.rs", "extern crate foo;");
+
+    assert_that(p.cargo_process("build"),
+                execs().with_status(0).with_stderr("\
+[UPDATING] registry [..]
+[DOWNLOADING] [..]
+[COMPILING] foo v0.1.0
+[COMPILING] a v0.0.1 ([..])
+[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
+"));
+}
+
 #[test]
 fn bad_target_spec() {
     let p = project("a")